<?php
/**
 * Created by PhpStorm.
 * User: lx
 * Date: 2020/1/10
 * Time: 10:21
 */
namespace app\hook\behavior;

use think\Db;
use think\facade\Hook;

/**
 * 商户后台管理系统请求日志钩子
 * Class AdminApiRequest
 * @package app\hook\behavior
 */
class AdminApiRequest
{
    public function run($param){
        $requestUrl = $_SERVER['REQUEST_URI']; // 请求路径
        $adminID = cache("adminUser.adminID"); // 请求人
        $requestUrlMethod = $_SERVER['REQUEST_METHOD']; // 请求方式
        $redirectStatus = $_SERVER['REDIRECT_STATUS']; // 返回状态
        $remoteAddr = ip2long($_SERVER['REMOTE_ADDR']); // 请求者的ip       // ip2long() ip转int long2ip() 数字转ip
        $time = $_SERVER['REQUEST_TIME']; // 请求时间
        $code = $param['code'];
        $msg = $param['msg'];
        Db::table("mt_admin_sys_log_request")->insert(
            [
                'timeID' => date("YmdHis"),
                'requestUrl' => $requestUrl,
                'adminID' => $adminID,
                'requestUrlMethod' => $requestUrlMethod,
                'redirectStatus' => $redirectStatus,
                'remoteAddr' => $remoteAddr,
                'time' => $time,
                'code' => $code,
                'msg' => $msg
            ]
        );
        return true;
    }
}